package com.itserver.controller.article;

import com.itserver.pojo.PageResult;
import com.itserver.pojo.Result;
import com.itserver.pojo.article.ArticleInfo;
import com.itserver.pojo.article.QueryArticleInfo;
import com.itserver.service.article.ArticleInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articleInfo")
public class ArticleInfoController {
    @Autowired
    private ArticleInfoService articleInfoService;

    @GetMapping
    public Result  list(QueryArticleInfo params){
        PageResult<ArticleInfo> pageResult = articleInfoService.list(params);
        return Result.success(pageResult);
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        articleInfoService.delete(ids);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody ArticleInfo articleInfo){
        articleInfoService.add(articleInfo);
        return Result.success();
    }
    @PostMapping("/publish")
    public Result publish(@RequestBody List<Integer> ids){
        articleInfoService.publish(ids);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody ArticleInfo articleInfo){
        articleInfoService.update(articleInfo);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        ArticleInfo articleInfo = articleInfoService.getById(id);
        return Result.success(articleInfo);
    }

}
